package com.goldcontrol.cloudweb.quartz;

import com.goldcontrol.cloudweb.quartz.job.*;
import com.goldcontrol.cloudweb.weixin.service.WeixinServiceApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class JobAutoRunService implements ApplicationRunner {

    @Autowired
    public SchedulerManager schedulerManager;

    @Autowired
    WeixinServiceApi weixinServiceApi;

    @Autowired
    InitJob initJob;

    @Autowired
    AccessJcmJob accessJcmJob;

    @Autowired
    AccessYsJob accessYsJob;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        weixinServiceApi.autoRefreshToken();
        weixinServiceApi.autoRefreshWeather();

//        accessJcmJob.execute(null);
//        accessYsJob.execute(null);

        initJob.execute();
        schedulerManager.startJob("0 0 0/1 * * ?","tokenJob","tokenJobGroup", TokenJob.class);
        schedulerManager.startJob("0 0/5 * * * ?","weatherJob","weatherJobGroup", WeatherJob.class);
        schedulerManager.startJob("0 0/5 * * * ?","ctrlJob","ctrlJobGroup", CtrlJob.class);
//        schedulerManager.startJob("0 0 0/1 * * ?","accessJcmJob","tokenJobGroup", AccessJcmJob.class);
//        schedulerManager.startJob("0 0 0/1 * * ?","accessYsJob","tokenJobGroup", AccessYsJob.class);
    }

}
